package com.tmans.common.util;
 
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class PingPoller
{
	
    public String  pingtest(String ipAddress)
    {
        System.out.println("Ping Poller Starts...");

       
        
        
        String stat ="";
        try
        {
            InetAddress inet = InetAddress.getByName(ipAddress);
            System.out.println("Sending Ping Request to " + ipAddress);

            boolean status = inet.isReachable(5000); //Timeout = 5000 milli seconds

            if (status)
            {
                System.out.println("Status : Host is reachable");
                stat="Y";
            }
            else
            {
                System.out.println("Status : Host is not reachable");
                stat="N";
            }
        }
        catch (UnknownHostException e)
        {
            System.err.println("Host does not exists");
            stat="NO";
        }
        catch (IOException e)
        {
            System.err.println("Error in reaching the Host");
            stat="E";
        }
        
        
		return stat;
        
        
    }
}